package com.song.my.imports;

import com.song.my.imports.service.IImportServiceTest;
import com.song.my.imports.service.MyImportServiceTest;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.lang.reflect.Proxy;

/**
 * @Description: MyImportBeanPostProcessorProxy：类描述
 * @author: songzhangyong
 * @Date: 2019/11/7 10:36
 */
public class MyImportBeanPostProcessorProxy implements BeanPostProcessor {

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if ("myImportServiceTest".equalsIgnoreCase(beanName)){
			bean = Proxy.newProxyInstance(this.getClass().getClassLoader() ,
					new Class[]{IImportServiceTest.class} , new MyInvocationHandler(bean));
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		return null;
	}

}
